<?php
/**
 * Created by PhpStorm.
 * User: 86188
 * Date: 2020/11/7
 * Time: 10:54
 */

namespace app\http\controller;
use think\Controller;
use think\facade\Log;
use app\service\hzcityService;
class Myredis extends Controller
{
    public function test(){
        $redis = new \Redis();

        $redis->connect('127.0.0.1',6379);

        $id=2;


        $res = $redis->publish('uploadPayRecord',$id);
        var_dump($res);
    }
    //redis订阅
    public function sub(){
        $redis = new \Redis();
        $redis->pconnect('127.0.0.1',6379);
        $redis->auth('zaozao2019@');
        $redis->subscribe(array('uploadPayRecord'), array($this,"callback"));
    }


    public function callback($instance, $channelName, $message){


        if($channelName=="uploadPayRecord"){
            //接收发送的order_id
            $order_id=$message;
            $orderinfo=Db::table("car_order")->where("order_id",$order_id)->find();
            $hzcity=array();
            (new hzcityService())->uploadPayRecord($hzcity);
        }

    }
}